using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WPCoco
{
    public static class MatrixHelper
    {
        public static Matrix GetViewWorldMatrix(Node node)
        {
            Matrix m = Matrix.Identity;
            while (node!=null)
            {
                if (node is AffineNode) 
                {
                    AffineNode local = (AffineNode)node;
                    m = local.ViewWorldMatrix * m;
                }
                node = node.Owner;
            }
            return m;
        }

        public static Matrix GetWorldViewMatrix(Node node)
        {
            Matrix m = Matrix.Identity;
            while (node != null)
            {
                if (node is AffineNode)
                {
                    AffineNode local = (AffineNode)node;
                    m = m * local.WorldViewMatrix;
                }
                node = node.Owner;
            }
            return m;
        }

        public static Matrix CreateSkew(float skewX, float skewY)
        {
            return new Matrix(1, (float)Math.Tan(MathHelper.ToRadians(skewY)), 0, 0,
                              (float)Math.Tan(MathHelper.ToRadians(skewX)), 1, 0, 0,
                              0, 0, 1, 0,
                              0, 0, 0, 1);
        }
    }
}
